<script setup>
import { h, onMounted, ref, resolveDirective, withDirectives } from 'vue'
import {
  NAvatar,
  NButton,
  NCheckbox,
  NCheckboxGroup,
  NForm,
  NFormItem,
  NImage,
  NInput,
  NSpace,
  NSwitch,
  NTag,
  NPopconfirm,
  NLayout,
  NLayoutSider,
  NLayoutContent,
  NTreeSelect, NSelect, NFlex, useMessage, NDataTable
} from 'naive-ui'

import CommonPage from '@/components/page/CommonPage.vue'
import QueryBarItem from '@/components/query-bar/QueryBarItem.vue'
import CrudModal from '@/components/table/CrudModal.vue'
import CrudTable from '@/components/table/CrudTable.vue'
import {formatDate, formatDateTime, getToken, renderIcon} from '@/utils'
import { useCRUD } from '@/composables'
import api from '@/api'
import TheIcon from '@/components/icon/TheIcon.vue'
import { useUserStore } from '@/store'
const base_path = import.meta.env.VITE_BASE
import default_image from "@/assets/images/mz.jpg"

defineOptions({ name: '过期提醒' })
const instance = getCurrentInstance();
const nameFromInstance = instance?.type.name;

const $table = ref(null)
const queryItems = ref({})
const vPermission = resolveDirective('permission')
const message = useMessage()

const data = reactive({
  uploadAction: base_path+'/system/base/userimg',
  token: getToken(),
  data_ini:{
    type: [],
    category_id:[]
  },
   config:[],
   durgs:[],
    DrugsDepository:[],
    DrugsNumber:[],
    select_durg_id:null
})

const {
  modalVisible,
  modalTitle,
  modalAction,
  modalLoading,
  handleSave,
  modalForm,
  modalFormRef,
  handleEdit,
  handleDelete,
  handleAdd,
} = useCRUD({
  name: '过期提醒',
  initForm: {},
  doCreate: api.createDrugsBills,
  doUpdate: api.updateDrugsBills,
  doDelete: api.deleteDrugsBills,
  refresh: () => $table.value?.handlerefresh(),
})


onMounted(() => {
    queryItems.value.type=1
    $table.value?.handleSearch()
})

const columns = [
  {
    title: '单号',
    key: 'id',
    width: 30,
    align: 'center',
    ellipsis: { tooltip: true },
  },
    {
    title: '库房',
    key: 'depository_id',
    width: 60,
    align: 'center',
    render(row) {
      return h(NTag, { type: 'primary',size:"small",bordered:false, style: { margin: '2px 3px' } }, { default: () => row.depository_id })
    },
  },
    {
    title: '药品名称',
    key: 'drug_name',
    width: 60,
    align: 'center',
    render(row) {
      return h(NTag, { type: 'primary',size:"small",bordered:false, style: { margin: '2px 3px' } }, { default: () => row.drug_name })
    },
  },
{
    title: '规格',
    key: 'spec',
    width: 60,
    align: 'center',
    ellipsis: { tooltip: true },
  },
    {
    title: '单位',
    key: 'unit',
    width: 60,
    align: 'center',
    ellipsis: { tooltip: true },
  },

    {
    title: '数量',
    key: 'free_number',
    width: 60,
    align: 'center',
    ellipsis: { tooltip: true },
  },
    {
    title: '单价',
    key: 'unit_price',
    width: 60,
    align: 'center',
    ellipsis: { tooltip: true },
  },
    {
    title: '过期时间',
    key: 'valid_at',
    width: 60,
    align: 'center',
    ellipsis: { tooltip: true },
  },

]

</script>

<template>
  <NLayout has-sider wh-full>
    <NLayoutContent style="background: transparent;margin-left: 20px;">
      <CommonPage show-footer :title="nameFromInstance+'列表'">

        <!-- 表格 -->
        <CrudTable
          ref="$table"
          v-model:query-items="queryItems"
          :columns="columns"
          :get-data="api.getDrugsBillsDetailList"
           :scroll-x="1200"
        >
          <template #queryBar>
<QueryBarItem label="药品名称" :label-width="80">
              <NInput
                v-model:value="queryItems.title"
                clearable
                type="text"
                placeholder="药品名称"
                style="width: 200px;"
              />
            </QueryBarItem>

          </template>
        </CrudTable>


      </CommonPage>
    </NLayoutContent>
  </NLayout>
  <!-- 业务页面 -->
</template>
